/*
 * User: rant
 * Date: Aug 1, 2007
 *
 *
 */
package laMalinche.actObservable;

import laMalinche.DerivationAdviser;
import laMalinche.rete.rule.DerivationListener;
import laMalinche.rete.rule.FieldAction;

import java.util.*;
import static java.lang.Boolean.*;

/**
 *
 */
public class FieldRuleObservableAction extends BasicObservableAction implements DerivationAdviser,FieldAction {

	private final List<DerivationListener> listenrs = new ArrayList<DerivationListener>();

//	 private String fieldOgnl;

	public FieldRuleObservableAction(final FieldAction action) {
		super(action);
	}

	public String getFieldOgnl() {
		return getAction().getFieldOgnl();
	}

//	public void setFieldOgnl(final String fieldOgnl) {
//		this.fieldOgnl = fieldOgnl;
//	}

	@Override
	protected void adviseFinished(boolean executed) {
		super.adviseFinished(executed);
			adviseRuleConcludedListeners(executed);
	}

	private void adviseRuleConcludedListeners(boolean exececuted) {
		for (DerivationListener derivationListener: listenrs){
			derivationListener.derivationRuleConcluded( getFieldOgnl(), exececuted);
		}
	}
	public void addDerivationListener(final DerivationListener derivationListener) {
		listenrs.add(derivationListener);
	}

	@Override
	protected Set<String> getExcludedFields() {
	Set<String> set = new HashSet<String>();
	set.add(getFieldOgnl());
		return set;
	}



public void informRuleUpdated(final Boolean met){
		if (FALSE.equals(met)) {
			adviseRuleConcludedListeners(true);
		}
}

@Override
public  FieldAction getAction(){
	 return (FieldAction) super.getAction();
 }
}